﻿using System;
using System.Linq;
using System.Web.UI;
using Test.DAL;
using Test.IDAL;

namespace Test
{
    public partial class ClassInfoUpdate : System.Web.UI.Page
    {
        IClassInfoDAL bll = new ClassInfoDAL();
        protected void Page_Load(object sender, EventArgs e)
        {
            UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
            if (!IsPostBack) {
            int id = Convert.ToInt32(Request.QueryString["Id"]);
                
            var info = bll.Single(id);
            if (info != null)
            {
                Text1.Value = info.Data.Id + "";
                TextBox1.Value = info.Data.Name;
                TextBox2.Text = info.Data.content;
            }
            else {
                Response.Redirect("~/ClassInfo.aspx");
            }
            
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Model.ClassInfo info = new Model.ClassInfo()
            {
                Id = Convert.ToInt32(Text1.Value),
                Name = TextBox1.Value,
                content = TextBox2.Text
            };
            var result = bll.Update(info);
            if (result.States && result.Data > 0)
            {
                Response.Write("<script>alert('修改成功');location='ClassInfo.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('" + result.message + "')</script>");
            }
           
        }
    }
}